package com.kcwl.idea.plugins.gateway.config;

import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class KcGatewaySettingsConfiguration implements Configurable {

    private KcGatewaySettingsForm form;

    @Override
    public @Nls(capitalization = Nls.Capitalization.Title) String getDisplayName() {
        return "Gateway Settings";
    }

    @Override
    public @Nullable JComponent createComponent() {
        if (form == null) {
            form = new KcGatewaySettingsForm();
        }
        return form.getPanel();
    }

    @Override
    public boolean isModified() {
        KcGatewaySettings settings = KcGatewaySettings.getInstance();
        KcGatewaySettings data = form.get();
        return !settings.equals(data);
    }

    @Override
    public void apply() throws ConfigurationException {
        KcGatewaySettings data = form.get();
        KcGatewaySettings.storeInstance(data);
    }

    @Override
    public void reset() {
        KcGatewaySettings settings = KcGatewaySettings.getInstance();
        form.set(settings);
    }
}
